//
//  UIBarButtonItem+Extension.swift
//  MyWeibo
//
//  Created by 昌俊 杨 on 29/9/2016.
//  Copyright © 2016 April. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    
    /// 带文本创建barbutton
    ///
    /// - parameter title:    标题
    /// - parameter fontSize: 字体大小
    /// - parameter target:   目标
    /// - parameter action:   事件
    /// - parameter isback:   是否是pop事件
    ///
    /// - returns: barbuttonItem
    convenience init(title:String,fontSize: CGFloat = 16,target: Any?,action:Selector,isback:Bool = false) {
       
        let btn = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: #colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1), highlightedColor: #colorLiteral(red: 1, green: 0.5106488466, blue: 0.002952917945, alpha: 1))
        btn?.addTarget(target, action: action, for: .touchUpInside)
        
        if isback
        {
            let imageName = "navigationbar_back_withtext"
            btn?.setImage(UIImage(named: imageName), for: .normal)
            btn?.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            btn?.sizeToFit()
        }
        
        self.init(customView: btn!)
    }
}
